package com.xue.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xue.bean.Order;
import com.xue.mapper.OrderMapper;
import com.xue.service.IOrderProService;
import com.xue.util.StringUtil;

@Service
@Component
public class OrderProServiceImpl implements IOrderProService{

	@Resource
	OrderMapper orderMapper;
	
	
	@Override
	public List<Order> selectOrderList(Order order) {
		List<Order> list = orderMapper.selectOrderList(order);
		return list;
	}

	@Override
	public Order SelectOrderById(Order roder) {
		Order o = orderMapper.SelectOrderById(roder);
		return o;
	}
	@Transactional(rollbackFor = {RuntimeException.class, Error.class})
	@Override
	public Map<String,String> saveOrder(Order order) {
		String orderId = StringUtil.getId();
		order.setOrderId(orderId);
		order.setValidStsCd("1");		
		Map<String,String> map = new HashMap<String,String>();
		//try {
		int rnum = orderMapper.saveOrder(order);
		if(rnum>0) {
			map.put("rtnCd", "00");
			map.put("rntMsg", "保存成功");
		}else {
			map.put("rtnCd", "9999");
			map.put("rntMsg", "保存失敗");			
		}	
		return map;
	}

	@Override
	public Map<String,String> updateOrderById(Order order) {		
		int rnum = orderMapper.updateOrderById(order);
		Map<String,String> map = new HashMap<String,String>();
		if(rnum>0) {
			map.put("rtnCd", "00");
			map.put("rntMsg", "更新成功");
		}else {
			map.put("rtnCd", "9999");
			map.put("rntMsg", "更新失敗");			
		}
		return map;
	}

	@Override
	public Map<String,String> delOrderById(Order order) {		
		int rnum = orderMapper.delOrderById(order);
		Map<String,String> map = new HashMap<String,String>();
		if(rnum>0) {
			map.put("rtnCd", "00");
			map.put("rntMsg", "删除成功");
		}else {
			map.put("rtnCd", "9999");
			map.put("rntMsg", "删除失敗");			
		}
		return map;
	}

}
